Add label to DifficultyBudget.Rating; guard zero player count in rating factory#25
Merged
Merged
Conversation
…count Moves the difficulty label switch from DifficultyAssessorView into the model so any view gets the canonical label without a local switch. Also guards against a zero-player party, which produces a meaningless budget, by returning nil from the rating factory. Closes #24
…ount - Nest `Category: String, Sendable` enum inside `Rating` with six cases (tooEasy, wellMatched, onBudget, challenging, dangerous, likelyTPK) and a `displayName` property that returns the raw-value string - Replace `label: String` (extension) with `category: Category` and `displayName: String` as struct members; drop the trailing extension - Extend nil guard in `rating(...)` to cover negative playerCount - Update tests: rename labelXxx → categoryXxx, compare against enum cases instead of string literals, add negative-playerCount nil test and displayName round-trip test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #24.
DifficultyBudget.Rating.Category— new nested enum with six typed cases (tooEasy,wellMatched,onBudget,challenging,dangerous,likelyTPK), each carrying its display string as the raw value.Category.displayNamereturnsrawValue.DifficultyBudget.Rating.category: Category— computed property that mapsremainingto the enum case using the authoritative thresholds fromDifficultyAssessorView.DifficultyBudget.Rating.displayName: String— convenience shim; equivalent tocategory.displayName.rating(adversaryTypes:playerCount:budgetAdjustment:)returnsRating?— guardsplayerCount > 0; returnsnilfor zero or negative player counts. Callers decide how to render the absence.Breaking change
rating(adversaryTypes:playerCount:budgetAdjustment:)now returnsRating?instead ofRating. A semver major version bump is required on the next release.Test plan
ratingWithinBudgetIsBalanced,ratingOverBudgetShowsNegativeRemaining,ratingWithBudgetAdjustmentupdated tothrows+try #require(...)ratingReturnsNilForZeroPlayers— nil forplayerCount: 0ratingReturnsNilForNegativePlayers— nil forplayerCount: -1categoryTooEasythroughcategoryLikelyTPK— two boundary values each, comparing against typed enum cases (not strings)displayNameMatchesCategoryRawValue— verifiesdisplayName == category.rawValueswift test --filter DHModelsTests— 94 tests, 0 failures./Scripts/format.sh— clean lintFollow-up (Encounter repo)
DifficultyAssessorViewandEncounterLibraryRowcan now replace their localswitch rating.remainingwithrating.category(for branching) orrating.displayName(for display). Tracked in Encounter #91.